//
//  MSFinancialReportController.m
//  觅尚
//
//  Created by No.8 on 2019/4/6.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSFinancialReportController.h"
#import "MSReportCell.h"
#import "ScanningViewController.h"

@interface MSFinancialReportController ()<UITableViewDelegate,UITableViewDataSource>
//通用导航栏
{
    CustomNavigationBar *naviagtionBar;
    
}
/** 表视图*/
@property(nonatomic,strong)UITableView *tableView;

/** 取反*/
@property(nonatomic,strong)UIButton *typeButton;

/** 遮盖层*/
@property(nonatomic,strong)UIView *backView;


/** 弹出View*/
@property(nonatomic,strong)UIView *showView;

@end

@implementation MSFinancialReportController

/** Nav实现 */
- (int)navBarBottom {
    if ([WRNavigationBar isIphoneX]) {
        return 88;
    } else {
        return 64;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
    self.view.backgroundColor = backgroundcolor;
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self CreateNavigationBar];
    
    [self CreatView];
    
    [self tableView];
}
- (void)CreatView{
    
    UIView * HeaderView = [[UIView alloc] init];
    HeaderView.x = 0;
    HeaderView.x = 0;
    HeaderView.width = ScreenWidth;
    HeaderView.backgroundColor = backgroundcolor;
    
    //    self.CollectionHeaderView = HeaderView;
    
    /** 房间总量*/
    UILabel * totleCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(40 * px, 40 * px, ScreenWidth / 3 * 2, 60 * px)];
    totleCountLabel.textColor = [UIColor whiteColor];
    totleCountLabel.text = @"今日总额     ￥1800";
    totleCountLabel.textAlignment = NSTextAlignmentLeft;
    totleCountLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [HeaderView addSubview:totleCountLabel];
    
    
    
    
    
    
    UIView * titleView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(totleCountLabel.frame) + 20 * px, HeaderView.width, 120 * px)];
    titleView.backgroundColor = BackViewColor;
    [HeaderView addSubview:titleView];
    NSArray * titleArray = @[@"日期",@"卡号",@"金额"];
    
    CGFloat CommoditytitleWidth = HeaderView.width / titleArray.count;
    CGFloat CommoditytitleY = 0;
    CGFloat CommoditytitleHeight = titleView.height;
    for (int index = 0; index < titleArray.count; index ++) {
        /** 标题label*/
        UILabel * Commoditytitle = [[UILabel alloc] init];
        Commoditytitle.x = CommoditytitleWidth * index;
        Commoditytitle.y = CommoditytitleY;
        Commoditytitle.width = CommoditytitleWidth;
        Commoditytitle.height = CommoditytitleHeight;
        Commoditytitle.textColor = WYCRGBColor(102, 121, 145);
        Commoditytitle.text = titleArray[index];
        Commoditytitle.textAlignment = NSTextAlignmentCenter;
        Commoditytitle.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
        [titleView addSubview:Commoditytitle];
    }
    
    HeaderView.height = CGRectGetMaxY(titleView.frame);
    [self.view addSubview:HeaderView];
    self.tableView.tableHeaderView = HeaderView;
    
    
    UIButton * bottomButton = [[UIButton alloc] initWithFrame:CGRectMake(0, ScreenHeight - 150 * px, ScreenWidth, 150 * px)];
    [bottomButton setTitle:@"开卡" forState:UIControlStateNormal];
    bottomButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [bottomButton setBackgroundImage:[UIImage imageNamed:@"底部按钮背景"] forState:UIControlStateNormal];
    [bottomButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [bottomButton addTarget:self action:@selector(playCardButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:bottomButton];
    
}
/** 表视图*/
- (UITableView *)tableView{
    self.extendedLayoutIncludesOpaqueBars = YES;
    if (!_tableView) {
        
        if (@available(iOS 11.0, *)) {
            
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            
        } else {
            
            self.automaticallyAdjustsScrollViewInsets = NO;
            
        }
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, [self navBarBottom], ScreenWidth, ScreenHeight - [self navBarBottom]) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:self.tableView];
    }
    return _tableView;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

//返回每组头部view

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *headerView = [[UIView alloc]init];
    
    headerView.backgroundColor = WYCRGBColor(20, 33, 48);
    
    
    //图片
    UIImageView *CheckIMG = [[UIImageView alloc] initWithFrame:CGRectMake(60 * px, 25 * px, 60 * px, 60 * px)];
    [headerView addSubview:CheckIMG];
    
    
    //标题
    UILabel * Titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(CheckIMG.frame) + 10 * px, 25 * px, 230 * px, 60 * px)];
    Titlelabel.textColor = [UIColor whiteColor];
    Titlelabel.font = [UIFont boldSystemFontOfSize:SYRealValue(28 / 2)];
    [headerView addSubview:Titlelabel];
    
    //时间图片
    UIImageView *TimeIMG = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(Titlelabel.frame), 40 * px, 50 * px, 50 * px)];
    [headerView addSubview:TimeIMG];
    
    
    
    
    //时间
    UILabel * Timelabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(TimeIMG.frame) + 10 * px, TimeIMG.y, 350 * px, 60 * px)];
    Timelabel.textColor = WYCRGBColor(139, 149, 171);
    Timelabel.font = [UIFont boldSystemFontOfSize:SYRealValue(26 / 2)];
    [headerView addSubview:Timelabel];
    
    
    //详情按钮
    UIButton * detailedButton = [[UIButton alloc] initWithFrame:CGRectMake( ScreenWidth - 270 * px, Titlelabel.y, Titlelabel.width, Titlelabel.height)];
    //设置边框的颜色
    [detailedButton.layer setBorderColor:WYCRGBColor(80, 112, 148).CGColor];
    detailedButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    //设置边框的粗细
    [detailedButton.layer setBorderWidth:1.0];
    [detailedButton setTitleColor:WYCRGBColor(59, 84, 112) forState:UIControlStateNormal];
    detailedButton.layer.cornerRadius = detailedButton.height * 0.5;
    [headerView addSubview:detailedButton];
    
    
    
    if (section == 0) {
        
        CheckIMG.image = [UIImage imageNamed:@"kqxx_icon"];
        [detailedButton setTitle:@"考勤统计" forState:UIControlStateNormal];
        [detailedButton addTarget:self action:@selector(CheckButtonClick) forControlEvents:UIControlEventTouchUpInside];
        Titlelabel.text = @"考勤信息";
        
        //        Timelabel.text = @"更新时间：03.15";
        
    }else if (section == 1) {
        
        CheckIMG.image = [UIImage imageNamed:@"fjgl_icon"];
        [detailedButton setTitle:@"房间详情" forState:UIControlStateNormal];
        Titlelabel.text = @"房间管理";
        TimeIMG.image = [UIImage imageNamed:@"gxxj_icon"];
        [detailedButton addTarget:self action:@selector(RoomButtonClick) forControlEvents:UIControlEventTouchUpInside];
        Timelabel.text = @"更新时间：03.15";
        
    }else if (section == 2) {
        CheckIMG.image = [UIImage imageNamed:@"yybb_icon"];
        [detailedButton setTitle:@"统计详情" forState:UIControlStateNormal];
        Titlelabel.text = @"营业报表";
        [detailedButton addTarget:self action:@selector(BusinessButtonClick) forControlEvents:UIControlEventTouchUpInside];
        TimeIMG.image = [UIImage imageNamed:@"gxxj_icon"];
        Timelabel.text = @"更新时间：03.15";
        
    }else {
        CheckIMG.image = [UIImage imageNamed:@"smhd_icon"];
        [detailedButton setTitle:@"统计详情" forState:UIControlStateNormal];
        [detailedButton addTarget:self action:@selector(SweepButtonClick) forControlEvents:UIControlEventTouchUpInside];
        Titlelabel.text = @"扫码活动";
        
    }
    
    return headerView;
    
}
// 返回组头部view的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 130 * px;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 2) {
        return 5;
    }else{
        return 1;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 500 * px;
    }else if (indexPath.section == 1){
        return 800 * px;
    }else if (indexPath.section == 3){
        return 700 * px;
    }else{
        if (indexPath.row == 0){
            return 400 * px;
        }else{
            
            return 300 * px;
        }
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    MSReportCell * cell = [MSReportCell cellWithTableView:tableView];
    tableView.backgroundColor = [UIColor clearColor];
    //无色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)CreateNavigationBar{
    
    self.view.backgroundColor = backgroundcolor;
    naviagtionBar = [[CustomNavigationBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, [self navBarBottom])];
    [self.view addSubview:naviagtionBar];
    naviagtionBar.titleLabel.text = @"房间管理";
    naviagtionBar.rightBtn.hidden = YES;
    naviagtionBar.rightBtnTitle.hidden = YES;
    [self.view addSubview:naviagtionBar];
    
    [naviagtionBar.leftBtn setImage:[UIImage imageNamed:@"左箭头"] forState:UIControlStateNormal];
    [naviagtionBar.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:NO];
}

- (void)playCardButton{
    
    UIView * view = [[UIView alloc] init];
    view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    [[UIApplication sharedApplication].keyWindow  addSubview:view];
    self.backView = view;
    
    
    UIView * showView = [[UIView alloc] init];
    showView.frame = CGRectMake(100 * px, ScreenHeight / 4, ScreenWidth - 200 * px, ScreenHeight / 2);
    showView.backgroundColor = [UIColor whiteColor];
    showView.layer.cornerRadius = 20 * px;
    [view addSubview:showView];
    self.showView = showView;
    UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    
    [view addGestureRecognizer:tapGesturRecognizer];
    
    
    /** 标题*/
    UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 80 * px, showView.width, 60 * px)];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.text = @"开卡";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont boldSystemFontOfSize:SYRealValue(35 / 2)];
    [showView addSubview:titleLabel];
    
    
    
    /** 标题*/
    UILabel * timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(40 * px, CGRectGetMaxY(titleLabel.frame) + 100 * px, 120 * px, 80 * px)];
    timeLabel.textColor = [UIColor blackColor];
    timeLabel.text = @"日期:";
    timeLabel.textAlignment = NSTextAlignmentLeft;
    timeLabel.font = [UIFont systemFontOfSize:SYRealValue(32 / 2)];
    [showView addSubview:timeLabel];
    
    
    UITextField * timeField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(timeLabel.frame) + 20 * px, timeLabel.y, showView.width - 260 * px, titleLabel.height)];
    timeField.placeholder = @"2019.03.22";
    [timeField setValue:[UIFont systemFontOfSize:SYRealValue(32 / 2)] forKeyPath:@"_placeholderLabel.font"];
    timeField.backgroundColor = [UIColor clearColor];
    timeField.textColor = [UIColor blackColor];
    [showView addSubview:timeField];
    
    
    UIView * timeLinView = [[UIView alloc] init];
    timeLinView.frame = CGRectMake(timeLabel.x, CGRectGetMaxY(timeField.frame) + 20 * px, showView.width - 80 * px, 1);
    timeLinView.backgroundColor = DividinglineColor;
    [showView addSubview:timeLinView];
    
    
    
    /** 标题*/
    UILabel * CardNMLabel = [[UILabel alloc] initWithFrame:CGRectMake(timeLabel.x, CGRectGetMaxY(timeLinView.frame) + 80 * px, timeLabel.width, timeLabel.height)];
    CardNMLabel.textColor = timeLabel.textColor;
    CardNMLabel.text = @"卡号:";
    CardNMLabel.textAlignment = timeLabel.textAlignment;
    CardNMLabel.font = timeLabel.font;
    [showView addSubview:CardNMLabel];
    
    
    UITextField * CardNMField = [[UITextField alloc] initWithFrame:CGRectMake(timeField.x, CardNMLabel.y, timeField.width, timeField.height)];
    CardNMField.text = @"32222233";
    CardNMField.textAlignment = NSTextAlignmentRight;
    CardNMField.backgroundColor = timeField.backgroundColor;
    CardNMField.textColor = timeField.textColor;
    [showView addSubview:CardNMField];
    
    
    UIView * CardNMLinView = [[UIView alloc] init];
    CardNMLinView.frame = CGRectMake(timeLinView.x, CGRectGetMaxY(CardNMField.frame) + 20 * px, timeLinView.width, timeLinView.height);
    CardNMLinView.backgroundColor = DividinglineColor;
    [showView addSubview:CardNMLinView];
    
    
    
    /** 金额*/
    UILabel * MoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(timeLabel.x, CGRectGetMaxY(CardNMLinView.frame) + 80 * px, timeLabel.width, timeLabel.height)];
    MoneyLabel.textColor = timeLabel.textColor;
    MoneyLabel.text = @"金额:";
    MoneyLabel.textAlignment = timeLabel.textAlignment;
    MoneyLabel.font = timeLabel.font;
    [showView addSubview:MoneyLabel];
    
    
    UITextField * MoneyField = [[UITextField alloc] initWithFrame:CGRectMake(timeField.x, MoneyLabel.y, timeField.width, timeField.height)];
    MoneyField.text = @"￥1123344";
    MoneyField.textAlignment = CardNMField.textAlignment;
    MoneyField.backgroundColor = timeField.backgroundColor;
    MoneyField.textColor = FontColor;
    [showView addSubview:MoneyField];
    
    
    UIView * MoneyLinView = [[UIView alloc] init];
    MoneyLinView.frame = CGRectMake(timeLinView.x, CGRectGetMaxY(MoneyField.frame) + 20 * px, timeLinView.width, timeLinView.height);
    MoneyLinView.backgroundColor = DividinglineColor;
    [showView addSubview:MoneyLinView];
    
    
    
    UIButton * completeButton = [[UIButton alloc] initWithFrame:CGRectMake(30 * px, CGRectGetMaxY(MoneyLinView.frame) + 100 * px, showView.width - 60 * px, 120 * px)];
    [completeButton setTitle:@"完成" forState:UIControlStateNormal];
    completeButton.layer.cornerRadius = 60 * px;
    completeButton.layer.masksToBounds = YES;
    completeButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [completeButton setBackgroundImage:[UIImage imageNamed:@"底部按钮背景"] forState:UIControlStateNormal];
    [completeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [completeButton addTarget:self action:@selector(completeButtonClick) forControlEvents:UIControlEventTouchUpInside];
    //    [completeButton addTarget:self action:@selector(playCardButton) forControlEvents:UIControlEventTouchUpInside];
    [showView addSubview:completeButton];
    
}
-(void)tapAction:(id)tap
{
    [self.backView removeFromSuperview];
}
- (void)completeButtonClick{
    
    [self.backView removeFromSuperview];
    //    self.backView.hidden = YES;
}

@end
